#!/usr/bin/env python3

import pymysql as mysqldb

db = mysqldb.connect(host="localhost", user="root", passwd="123123")
db.autocommit(True)                 
cur = db.cursor()

'''show database'''
cur.execute("show databases;")
show = cur.fetchall()
print (show)

'''create database sanle_1'''
cur.execute("create database sanle_1;")
show = cur.fetchall()

'''create table in sanle_1 and name student'''
table_sql = '''create table if not exists sanle_1.student(
id int,
name varchar(10),
age int,
phone_num decimal(20),
address varchar(20),
major varchar(8),
primary key(id)
)'''
cur.execute(table_sql)

'''insert into data in studnet'''
insert_sql = '''insert into sanle_1.student(id,name,age,phone_num,address,major)values(1,"xiang",20,15217564509,"changsha_furong","it"),(2,"feng",34,15722360935,"changsha_furong","it"),(3,"yang",36,37856782245,"yueyang_miluo","ai");'''
cur.execute(insert_sql)

'''search table data'''
cur.execute("select * from sanle_1.student;")
da = cur.fetchall()

mysqldb.close()
